# -*- encoding:utf-8 -*-
# !/usr/bin/env python
'''
    python-0824-01.py
    ======================
    @descript: 线程池
    @copyright:nnz
    @author:dln
    @date: 2021/8/23 14:02
    @version:v1.0
'''
import threading
import time
from asyncio import Future
from concurrent.futures.thread import ThreadPoolExecutor


def f_call(pfture:Future):
    print('执行的结果为：{}'.format(threading.currentThread().getName(),pfture.result()))
    pass
def f_01(p_num):
    print('线程{}开始执行'.format(threading.currentThread().getName()))
    for element in range(1,p_num+1):
        print('{}输出的值为：{}'.format(threading.currentThread().getName(),element))
        time.sleep(1)
        pass
    print('线程{}结束执行'.format(threading.currentThread().getName()))
    return '线程{}执行结束'.format(threading.currentThread().getName())
if __name__=='__main__':
    v_pool=ThreadPoolExecutor(2)
    v_result:Future=v_pool.submit(f_01,5)     #取出第一个线程
    v_result01:Future=v_pool.submit(f_01,3)   #取出第二个线程
    v_pool.shutdown()                         #关闭线程，不能再添加内容到线程池里
    v_result.add_done_callback(f_call)
    v_result01.add_done_callback(f_call)
    pass